# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Thomas Dziedzic <gostrc@gmail.com>

_hkgname=foundation
pkgname=haskell-foundation
pkgver=0.0.30
pkgrel=11
pkgdesc="Alternative prelude with batteries and no dependencies"
url="https://github.com/haskell-foundation/foundation"
license=('BSD')
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'haskell-basement')
makedepends=('ghc' 'uusi' 'haskell-doctest')
source=("https://hackage.haskell.org/packages/archive/${_hkgname}/${pkgver}/${_hkgname}-${pkgver}.tar.gz")
sha512sums=('5b7a193a03f6f86f125a95363705c760f3ce8686720aa91e815daf131b42cb84a8fd39d448f4b2e803654e1e4764fdfea28918c4558c5f87451aa7c05714efda')

prepare() {
    cd $_hkgname-$pkgver
    gen-setup
}

build() {
    cd $_hkgname-$pkgver
    
    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --enable-tests \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm \
            -f-experimental -f-minimal-deps -f-doctest -flinktest -f-bounds-check
    runhaskell Setup build $MAKEFLAGS
    runhaskell Setup register --gen-script
    runhaskell Setup unregister --gen-script
    sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
    sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
    cd $_hkgname-$pkgver
    runhaskell Setup test --show-details=direct || echo "https://github.com/haskell-foundation/foundation/issues/560"
}

package() {
    cd $_hkgname-$pkgver
    
    install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
    install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
    runhaskell Setup copy --destdir="$pkgdir"
    install -D -m644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
    rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
